#include "threadpool.h"
#include<sys/sendfile.h>
int transferFile(int peerfd,const char*filename){
    train_t train;
    memset(&train,0,sizeof(train));
    //发文件名给对端
    train.length = strlen(filename);
    strncpy(train.data , filename,train.length);
    int ret = sendn(peerfd,&train,4+train.length);

    //读server本地的文件
    char sendBuff[SENDBUFFSIZE]={0};
    int fileFd = open("bigfile.avi",O_RDWR);
    //ret = read(fileFd,sendBuff,sizeof(sendBuff));
    
    //发送文件长度
    struct stat st;
    fstat(fileFd,&st);
    printf(">>file length:%ld\n",st.st_size);
    memset(&train,0,sizeof(train));
    train.length = sizeof(off_t);
    strncpy(train.data,(char*)&st.st_size,sizeof(off_t));
    ret = sendn(peerfd,&train,4+train.length);
    printf("child send %d bytes\n",ret);
    //发送文件内容
    ret = sendfile(peerfd,fileFd,NULL,st.st_size);
    printf("sendfile send over\n");
    close(fileFd);
    return 0;
}
